/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ueb17;

/**
 *
 * @author steffenschuhmann
 */
public class ExpressionNodeImpl {
    
    private long                value;
    private char                operator;
    private String              name;
    private long                pointer;
    private ExpressionNodeImpl  leftChild;
    private ExpressionNodeImpl  rightChild;
    
    public ExpressionNodeImpl(long pointer, String name) throws WrongOperatorException {
        if(name == null || name.equals(""))
            throw new NullPointerException();
        
        if(pointer < 0)
            throw new PointerException();
        
        this.name = name;
        this.pointer = pointer;
        this.operator = 'n';    
    }
    
    public ExpressionNodeImpl(char operator) throws WrongOperatorException {
        if(operator != '+' || operator != '-' || operator != '*' ||
                operator != '/' || operator != 'n' || operator != '('
                || operator != ')')
            throw new WrongOperatorException();
        
        this.operator = operator;
    }
    
    public void setLeftChild(ExpressionNodeImpl leftChild) {
        if(leftChild == null)
            throw new NullPointerException();
        this.leftChild = leftChild;
    }
    
    public void setRightChild(ExpressionNodeImpl rightChild) {
        if(rightChild == null)
            throw new NullPointerException();
        this.rightChild = rightChild;
    }
    
    public void setValue(long value) {
        this.value = value;
    }
    
    
    public ExpressionNodeImpl getRightChild() {
        return rightChild;
    }
    
    public ExpressionNodeImpl getLeftChild() {
        return leftChild;
    }
    
    public long getValue() {
        return value;
    }
    
    public char getOperator() {
        return operator;
    }
    
    public long getPointer() {
        return pointer;
    }
    
    public boolean isOperator() {
        if(operator != '+' || operator != '-' || operator != '*' ||
                operator != '/' || operator != 'n')
            return true;
        
        if(operator == 'n')
            return false;
        
        if(name == null)
            return true;
        
        return false;
    }
    
}
